home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Bowers Development / AppMaker 2.0b5 / Examples / ODF / AMSample / Sources / Commands.cpp < prev    next >
Encoding:
Text File  |  1996-06-03  |  9.1 KB  |  286 lines  |  [TEXT/CWIE]

  1. //========================================================================================
  2. //
  3. //    File:                Commands.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "AMSample.hpp"
  11.  
  12. #ifndef COMMANDS_H
  13. #include "Commands.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef CONTENT_H
  21. #include "Content.h"
  22. #endif
  23.  
  24. // ----- Framework Includes -----
  25.  
  26. #ifndef FWPRESEN_H
  27. #include "FWPresen.h"
  28. #endif
  29.  
  30. // ----- OpenDoc Includes -----
  31.  
  32. #ifndef SOM_Module_OpenDoc_Commands_defined
  33. #include <CmdDefs.xh>
  34. #endif
  35.  
  36. //========================================================================================
  37. // RunTime Info
  38. //========================================================================================
  39.  
  40. #ifdef FW_BUILD_MAC
  41. #pragma segment AMSample
  42. #endif
  43.  
  44. FW_DEFINE_AUTO(CAMSampleEditCommand)
  45. FW_DEFINE_AUTO(CAMSampleDropCommand)
  46. FW_DEFINE_AUTO(CAMSampleDragCommand)
  47.  
  48. //========================================================================================
  49. // CAMSampleEditCommand
  50. //========================================================================================
  51.  
  52. //----------------------------------------------------------------------------------------
  53. //    CAMSampleEditCommand constructor
  54. //----------------------------------------------------------------------------------------
  55.  
  56. CAMSampleEditCommand::CAMSampleEditCommand(Environment* ev,
  57.                                      ODCommandID id,
  58.                                      CAMSampleContent* itsContent,
  59.                                      FW_CFrame* frame) :
  60.     FW_CClipboardCommand(ev, id, frame, FW_kCanUndo),
  61.     fAMSampleContent(itsContent)
  62. {
  63.     switch (id)
  64.     {
  65.         case kODCommandCut:
  66.             SetMenuStringsFromResource(ev, kAMSampleUndoStrings, kUndoCutTextMsg, kRedoCutTextMsg);
  67.             break;
  68.         case kODCommandClear:
  69.             SetMenuStringsFromResource(ev, kAMSampleUndoStrings, kUndoClearTextMsg, kRedoClearTextMsg);
  70.             break;
  71.         case kODCommandPaste:
  72.             SetMenuStringsFromResource(ev, kAMSampleUndoStrings, kUndoPasteTextMsg, kRedoPasteTextMsg);
  73.             break;
  74.     }
  75.     FW_END_CONSTRUCTOR
  76. }
  77.  
  78. //----------------------------------------------------------------------------------------
  79. //    CAMSampleEditCommand destructor
  80. //----------------------------------------------------------------------------------------
  81.  
  82. CAMSampleEditCommand::~CAMSampleEditCommand()
  83. {
  84. }
  85.  
  86. //----------------------------------------------------------------------------------------
  87. //    CAMSampleEditCommand::SaveUndoState
  88. //----------------------------------------------------------------------------------------
  89.  
  90. void CAMSampleEditCommand::SaveUndoState(Environment *ev)
  91. {
  92.      fSavedTextData = fAMSampleContent->GetTextData();
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. //    CAMSampleEditCommand::UndoIt
  97. //----------------------------------------------------------------------------------------
  98.  
  99. void CAMSampleEditCommand::UndoIt(Environment* ev)
  100. {
  101.     FW_CClipboardCommand::UndoIt(ev);    // call inherited
  102.  
  103.     switch (GetCommandID(ev))
  104.     {
  105.         case kODCommandCut:
  106.         case kODCommandClear:
  107.             this->RestoreSelection(ev);
  108.             break;
  109.  
  110.         case kODCommandPaste:
  111.             this->SwapSelection(ev);
  112.             break;
  113.     }    
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    CAMSampleEditCommand::RedoIt
  118. //----------------------------------------------------------------------------------------
  119.  
  120. void CAMSampleEditCommand::RedoIt(Environment *ev)
  121. {
  122.     FW_CClipboardCommand::RedoIt(ev);    // call inherited
  123.  
  124.     switch (GetCommandID(ev))
  125.     {
  126.         case kODCommandCut:
  127.         case kODCommandClear:
  128.             this->RemoveSelection(ev);
  129.             break;
  130.  
  131.         case kODCommandPaste:
  132.             this->SwapSelection(ev);
  133.             break;
  134.     }    
  135. }
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    CAMSampleEditCommand::RemoveSelection
  139. //----------------------------------------------------------------------------------------
  140.  
  141. void CAMSampleEditCommand::RemoveSelection(Environment* ev)
  142. {
  143.     fAMSampleContent->ClearTextData(ev);
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. //    CAMSampleEditCommand::RestoreSelection
  148. //----------------------------------------------------------------------------------------
  149.  
  150. void CAMSampleEditCommand::RestoreSelection(Environment* ev)
  151. {
  152.     fAMSampleContent->SetTextData(ev, fSavedTextData);
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    CAMSampleEditCommand::SwapSelection
  157. //----------------------------------------------------------------------------------------
  158.  
  159. void CAMSampleEditCommand::SwapSelection(Environment* ev)
  160. {
  161.     FW_CString255 textData = fAMSampleContent->GetTextData();
  162.     fAMSampleContent->SetTextData(ev, fSavedTextData);
  163.     fSavedTextData = textData;
  164. }
  165.  
  166. //========================================================================================
  167. // CAMSampleDragCommand
  168. //========================================================================================
  169.  
  170. //----------------------------------------------------------------------------------------
  171. //    CAMSampleDragCommand constructor
  172. //----------------------------------------------------------------------------------------
  173.  
  174. CAMSampleDragCommand::CAMSampleDragCommand(Environment* ev,
  175.                                      CAMSampleContent* content,
  176.                                      FW_CFrame* frame) :
  177.     FW_CDragCommand(ev, frame, FW_kCanUndo),
  178.     fAMSampleContent(content)
  179. {
  180.     SetMenuStringsFromResource(ev, kAMSampleUndoStrings, kUndoDragTextMsg, kRedoDragTextMsg);
  181.     FW_END_CONSTRUCTOR
  182. }
  183.  
  184. //----------------------------------------------------------------------------------------
  185. //    CAMSampleDragCommand destructor
  186. //----------------------------------------------------------------------------------------
  187.  
  188. CAMSampleDragCommand::~CAMSampleDragCommand()
  189. {
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    CAMSampleDragCommand::SaveUndoState
  194. //----------------------------------------------------------------------------------------
  195.  
  196. void CAMSampleDragCommand::SaveUndoState(Environment *ev)
  197. {
  198.      fSavedTextData = fAMSampleContent->GetTextData();
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. //    CAMSampleDragCommand::UndoIt
  203. //----------------------------------------------------------------------------------------
  204.  
  205. void CAMSampleDragCommand::UndoIt(Environment* ev)
  206. {
  207.     fAMSampleContent->SetTextData(ev, fSavedTextData);
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //    CAMSampleDragCommand::RedoIt
  212. //----------------------------------------------------------------------------------------
  213.  
  214. void CAMSampleDragCommand::RedoIt(Environment* ev)
  215. {
  216.     fAMSampleContent->ClearTextData(ev);
  217. }
  218.  
  219. //========================================================================================
  220. // CAMSampleDropCommand
  221. //========================================================================================
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    CAMSampleDropCommand constructor
  225. //----------------------------------------------------------------------------------------
  226.  
  227. CAMSampleDropCommand::CAMSampleDropCommand(Environment *ev,
  228.                                      CAMSampleContent* content,
  229.                                      FW_CFrame* frame,
  230.                                      ODDragItemIterator* dropInfo, 
  231.                                      ODFacet* odFacet,
  232.                                      const FW_CPoint& dropPoint) : 
  233.     FW_CDropCommand(ev, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
  234.     fAMSampleContent(content)
  235. {
  236.     SetMenuStringsFromResource(ev, kAMSampleUndoStrings, kUndoDropTextMsg, kRedoDropTextMsg);
  237.     FW_END_CONSTRUCTOR
  238. }
  239.  
  240. //----------------------------------------------------------------------------------------
  241. //    CAMSampleDropCommand destructor
  242. //----------------------------------------------------------------------------------------
  243.  
  244. CAMSampleDropCommand::~CAMSampleDropCommand()
  245. {
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    CAMSampleDropCommand::SaveUndoState
  250. //----------------------------------------------------------------------------------------
  251.  
  252. void CAMSampleDropCommand::SaveUndoState(Environment *ev)
  253. {
  254.      fSavedTextData = fAMSampleContent->GetTextData();
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. //    CAMSampleDropCommand::UndoIt
  259. //----------------------------------------------------------------------------------------
  260.  
  261. void CAMSampleDropCommand::UndoIt(Environment* ev)
  262. {
  263.     this->SwapSelection(ev);
  264. }
  265.  
  266. //----------------------------------------------------------------------------------------
  267. //    CAMSampleDropCommand::RedoIt
  268. //----------------------------------------------------------------------------------------
  269.  
  270. void CAMSampleDropCommand::RedoIt(Environment* ev)
  271. {
  272.     this->SwapSelection(ev);
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    CAMSampleDropCommand::SwapSelection
  277. //----------------------------------------------------------------------------------------
  278.  
  279. void CAMSampleDropCommand::SwapSelection(Environment* ev)
  280. {
  281.     FW_CString255 textData = fAMSampleContent->GetTextData();
  282.     fAMSampleContent->SetTextData(ev, fSavedTextData);
  283.     fSavedTextData = textData;
  284. }
  285.  
  286.